{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "70057ee8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "57a39ba1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>每月支出</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>编号</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6807.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4780.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1959.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5011.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4557.21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2170</th>\n",
       "      <td>4373.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2171</th>\n",
       "      <td>7486.03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2172</th>\n",
       "      <td>6476.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2173</th>\n",
       "      <td>122.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2174</th>\n",
       "      <td>3912.25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2175 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         每月支出\n",
       "编号           \n",
       "0     6807.50\n",
       "1     4780.45\n",
       "2     1959.00\n",
       "3     5011.06\n",
       "4     4557.21\n",
       "...       ...\n",
       "2170  4373.94\n",
       "2171  7486.03\n",
       "2172  6476.80\n",
       "2173   122.55\n",
       "2174  3912.25\n",
       "\n",
       "[2175 rows x 1 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pay = pd.read_csv('data/user_pay_info.csv',index_col=0)\n",
    "pay"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df98fd2d",
   "metadata": {},
   "source": [
    "离差标准化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "25dfa27f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def min_max_scale(data):\n",
    "    data = (data-data.min())/(data.max()-data.min())\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "430b3415",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "编号\n",
       "0       0.615543\n",
       "1       0.431867\n",
       "2       0.176208\n",
       "3       0.452763\n",
       "4       0.411638\n",
       "          ...   \n",
       "2170    0.395032\n",
       "2171    0.677026\n",
       "2172    0.585577\n",
       "2173    0.009803\n",
       "2174    0.353197\n",
       "Name: 每月支出, Length: 2175, dtype: float64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pay_min_max = min_max_scale(pay['每月支出'])\n",
    "pay_min_max"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9f622b0",
   "metadata": {},
   "source": [
    "标准差标准化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bd17b83f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def standard_scaler(data):\n",
    "    data = (data-data.mean())/data.std()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2ffd53f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "编号\n",
       "0       1.004110\n",
       "1       0.003042\n",
       "2      -1.390344\n",
       "3       0.116930\n",
       "4      -0.107206\n",
       "          ...   \n",
       "2170   -0.197715\n",
       "2171    1.339206\n",
       "2172    0.840793\n",
       "2173   -2.297284\n",
       "2174   -0.425722\n",
       "Name: 每月支出, Length: 2175, dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pay_standard = standard_scaler(pay['每月支出'])\n",
    "pay_standard"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4bf01852",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
